﻿using System;

namespace codejockey.BingPaper.Utils
{
  public class BingImageParams
  {
    #region Private Constants

    private const string BaseUrl = "http://www.bing.com";
    private const string RssUrlWithCountryCodeAndIndexParams = BaseUrl + "/HPImageArchive.aspx?format=xml&idx={0}&n=1&cc={1}";

    #endregion

    private Uri _uri;
    private string _countryCode;
    private int _dayIndex;

    public static bool Validate()
    {
      const bool result = true;

      return result;
    }

    public Uri Uri
    {
      get {
        return _uri ??
               (_uri =
                !string.IsNullOrEmpty(CountryCode)
                  ? new Uri(string.Format(RssUrlWithCountryCodeAndIndexParams, _dayIndex, _countryCode))
                  : new Uri(string.Format(RssUrlWithCountryCodeAndIndexParams, _dayIndex, BingUtils.CurrentCountryCode)));
      }

      set
      {
        _uri = value;
      }
    }

    public int DayIndex
    {
      get
      {
        return _dayIndex;
      }
      set
      {
        if (value > 7 || value < 0)
          throw new ApplicationException("The DayIndex value must be between 0-7.");

        if (_dayIndex != value)
          _uri = null;

        _dayIndex = value;
      }
    }

    public string CountryCode
    {
      get
      {
        return _countryCode;
      }

      set
      {
        if (_countryCode != value)
          _uri = null;

        _countryCode = value;
      }
    }

    public string Path { get; set; }

    public string File { get; set; }
  }
}
